home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTPtrSlist<T> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tpslist.h> RWTPtrSlist<T> list; PPPPlllleeeeaaaasssseeee NNNNooootttteeee!!!! IIIIffff yyyyoooouuuu ddddoooo nnnnooootttt hhhhaaaavvvveeee tttthhhheeee SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ddddeeeessssccccrrrriiiibbbbeeeedddd hhhheeeerrrreeee.... OOOOtttthhhheeeerrrrwwwwiiiisssseeee,,,, uuuusssseeee tttthhhheeee iiiinnnntttteeeerrrrffffaaaacccceeee ttttoooo RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt described in the Class Reference. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class maintains a collection of pointers to type TTTT, implemented as a singly-linked list. This is a ppppooooiiiinnnntttteeeerrrr based list: pointers to objects are copied in and out of the links that make up the list. Parameter TTTT represents the type of object to be inserted into the list, either a class or fundamental type. The class TTTT must have: well-defined equality semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr========((((ccccoooonnnnsssstttt TTTT&&&&))))). PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Isomorphic EEEExxxxaaaammmmpppplllleeee In this example, a singly-linked list of RRRRWWWWDDDDaaaatttteeeessss is exercised. #include <rw/tpslist.h> #include <rw/rwdate.h> #include <rw/rstream.h> main() { RWTPtrSlist<RWDate> dates; dates.insert(new RWDate(2, "June", 52)); // 6/2/52 dates.insert(new RWDate(30, "March", 46)); // 3/30/46 dates.insert(new RWDate(1, "April", 90)); // 4/1/90 // Now look for one of the dates: RWDate key(2, "June", 52); RWDate* d = dates.find(&key); if (d){ cout << "Found date " << *d << endl; } // Remove in reverse order: while (!dates.isEmpty()){ d = dates.removeLast(); PPPPaaaaggggeeee 1111 RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) cout << *d << endl; delete d; } return 0; } Program output: Found date June 2, 1952 April 1, 1990 March 30, 1946 June 2, 1952 PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt<T>(); Construct an empty list. RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt<T>(const RWTPtrSlist<T>& c); Constructs a new singly-linked list as a shallow copy of cccc. After construction, pointers will be shared between the two collections. PPPPuuuubbbblllliiiicccc OOOOppppeeeerrrraaaattttoooorrrrssss RWTPtrSlist& ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrSlist<T>& c); Sets self to a shallow copy of cccc. Afterwards, pointers will be shared between the two collections. T*& ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i); T* const& ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](size_t i) const; Returns a pointer to the iiiith value in the list. The first variant can be used as an llllvvvvaaaalllluuuueeee, the second cannot. The index iiii must be between zero and the number of items in the collection less one, or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppeeeennnndddd(T* a); Appends the item pointed to by aaaa to the end of the list. PPPPaaaaggggeeee 2222 RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) void aaaappppppppllllyyyy(void (*applyFun)(T*, void*), void* d); Applies the user-defined function pointed to by aaaappppppppllllyyyyFFFFuuuunnnn to every item in the list. This function must have the prototype: void yyyyoooouuuurrrrFFFFuuuunnnn(T* a, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. T*& aaaatttt(size_t i); T* const; aaaatttt(size_t i) const; Returns a pointer to the iiiith value in the list. The first variant can be used as an llllvvvvaaaalllluuuueeee, the second cannot. The index iiii must be between zero and the number of items in the collection less one, or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown. void cccclllleeeeaaaarrrr(); Removes all items from the collection. void cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(); Removes all items from the collection aaaannnndddd deletes them. RWBoolean ccccoooonnnnttttaaaaiiiinnnnssss(const T* a) const; Returns TTTTRRRRUUUUEEEE if the list contains an object that is equal to the object pointed to by aaaa, FFFFAAAALLLLSSSSEEEE otherwise. Equality is measured by the class- defined equality operator for type TTTT. RWBoolean ccccoooonnnnttttaaaaiiiinnnnssss(RWBoolean (*testFun)(T*, void*),void* d) const; PPPPaaaaggggeeee 3333 RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) Returns TTTTRRRRUUUUEEEE if the list contains an item for which the user-defined "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE . Returns FFFFAAAALLLLSSSSEEEE otherwise. The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. size_t eeeennnnttttrrrriiiieeeessss() const; Returns the number of items that are currently in the collection. T* ffffiiiinnnndddd(const T* target) const; Returns a pointer to the first object encountered which is equal to the object pointed to by ttttaaaarrrrggggeeeetttt, or nnnniiiillll if no such object can be found. Equality is measured by the class-defined equality operator for type TTTT. T* ffffiiiinnnndddd(RWBoolean (*testFun)(T*, void*),void* d,) const; Returns a pointer to the first object encountered for which the user- defined tester function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE, or nnnniiiillll if no such object can be found. The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. T*& ffffiiiirrrrsssstttt(); T* const& ffffiiiirrrrsssstttt() const; PPPPaaaaggggeeee 4444 RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) Returns a pointer to the first item in the list. The behavior is undefined if the list is empty. T* ggggeeeetttt(); Returns a pointer to the first item in the list and removes the item. The behavior is undefined if the list is empty. size_t iiiinnnnddddeeeexxxx(const T* a); Returns the index of the first object that is equal to the object pointed to by aaaa, or RRRRWWWW____NNNNPPPPOOOOSSSS if there is no such object. Equality is measured by the class-defined equality operator for type TTTT. size_t iiiinnnnddddeeeexxxx(RWBoolean (*testFun)(T*, void*),void* d) const; Returns the index of the first object for which the user-defined tester function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE, or RRRRWWWW____NNNNPPPPOOOOSSSS if there is no such object. The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. void iiiinnnnsssseeeerrrrtttt(T* a); Adds the object pointed to by aaaa to the end of the list. void iiiinnnnsssseeeerrrrttttAAAAtttt(size_t i, T* a); Adds the object pointed to by aaaa at the index position iiii. This position must be between zero and the number of items in the list, or an exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown. PPPPaaaaggggeeee 5555 RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) RWBoolean iiiissssEEEEmmmmppppttttyyyy() const; Returns TTTTRRRRUUUUEEEE if there are no items in the list, FFFFAAAALLLLSSSSEEEE otherwise. T*& llllaaaasssstttt(); T* const& llllaaaasssstttt() const; Returns a pointer to the last item in the list. The behavior is undefined if the list is empty. size_t ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const T* a) const; Returns the number of objects in the list that are equal to the object pointed to by aaaa. Equality is measured by the class-defined equality operator for type TTTT. size_t ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(RWBoolean (*testFun)(T*, void*),void* d) const; Returns the number of objects in the list for which the user-defined "tester" function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE . The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. void pppprrrreeeeppppeeeennnndddd(T* a); Adds the item pointed to by aaaa to the beginning of the list. T* rrrreeeemmmmoooovvvveeee(const T* a); PPPPaaaaggggeeee 6666 RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) Removes the first object which is equal to the object pointed to by aaaa and returns a pointer to it, or nnnniiiillll if no such object could be found. Equality is measured by the class-defined equality operator for type TTTT. T* rrrreeeemmmmoooovvvveeee(RWBoolean (*testFun)(T*, void*),void* d); Removes the first object for which the user-defined tester function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE and returns a pointer to it, or nnnniiiillll if there is no such object. The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. size_t rrrreeeemmmmoooovvvveeeeAAAAllllllll(const T* a); Removes all objects which are equal to the object pointed to by aaaa. Returns the number of objects removed. Equality is measured by the class-defined equality operator for type TTTT. size_t rrrreeeemmmmoooovvvveeeeAAAAllllllll(RWBoolean (*testFun)(T*, void*),void* d); Removes all objects for which the user-defined tester function pointed to by tttteeeessssttttFFFFuuuunnnn returns TTTTRRRRUUUUEEEE. Returns the number of objects removed. The tester function must have the prototype: RWBoolean yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr(T*, void* d); This function will be called for each item in the list, with a pointer to the item as the first argument. Client data may be passed through as parameter dddd. T* rrrreeeemmmmoooovvvveeeeAAAAtttt(size_t i); PPPPaaaaggggeeee 7777 RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrSSSSlllliiiisssstttt((((3333CCCC++++++++)))) Removes the object at index iiii and returns a pointer to it. An exception of type RRRRWWWWBBBBoooouuuunnnnddddssssEEEErrrrrrrroooorrrr will be thrown if iiii is not a valid index. Valid indices are from zero to the number of items in the list less one. T* rrrreeeemmmmoooovvvveeeeFFFFiiiirrrrsssstttt(); Removes the first item in the list and returns a pointer to it. The behavior is undefined if the list is empty. T* rrrreeeemmmmoooovvvveeeeLLLLaaaasssstttt(); Removes the last item in the list and returns a pointer to it. The behavior is undefined if the list is empty. This function is relatively slow because removing the last link in a singly-linked list necessitates access to the next-to-the-last link, requiring that the whole list be searched. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrSlist<T>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrSlist<T>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrSlist<T>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrSlist<T>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrSlist<T>*& p); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrSlist<T>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 8888